import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	Scanner in;
	PrintWriter out;

	class Point {
		int x;
		int y;

		Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	boolean dfs(boolean[][] used, int curI, int curJ, int maxI, int maxJ) {
		if (curI == maxI - 1 && curJ == maxJ - 1) {
			return true;
		}
		if (used[curI][curJ]) {
			return false;
		}
		used[curI][curJ] = true;
		for (int di = -1; di <= 1; di++) {
			for (int dj = -1; dj <= 1; dj++) {
				if (di * di + dj * dj == 1) {
					if (0 <= curI + di && curI + di < maxI && 0 <= curJ + dj && curJ + dj < maxJ) {
						if (!used[curI + di][curJ + dj]) {
							if (dfs(used, curI + di, curJ + dj, maxI, maxJ)) {
								return true;
							}
						}
					}
				}
			}
		}
		return false;
	}

	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		boolean a[][] = new boolean[n][m];
		Point p[] = new Point[k];
		for (int i = 0; i < k; i++) {
			p[i] = new Point(in.nextInt() - 1, in.nextInt() - 1);
		}
		int left = 0;
		int right = k - 1;
		int back = -1;
		int answer = 0;
		while (true) {
			if (left > right) {
				break;
			}
			int mid = left + (right - left) / 2;
			if (mid > back) {
				for (int i = back + 1; i <= mid; i++) {
					a[p[i].x][p[i].y] = true;
				}
			} else {
				for (int i = mid + 1; i <= back; i++) {
					a[p[i].x][p[i].y] = false;
				}
			}
			back = mid;
			boolean[][] newA = new boolean[a.length][a[0].length];
			for (int i = 0; i < a.length; i++) {
				for (int j = 0; j < a[0].length; j++) {
					newA[i][j] = a[i][j];
				}
			}
			if (dfs(newA, 0, 0, n, m)) {
				left = mid + 1;
			} else {
				answer = mid;
				right = mid - 1;
			}
		}
		if (answer != 0) {
			answer++;
		}
		out.println(answer);
	}

	void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}
